﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.UI.Interfaces;

namespace Pahan.McuFusion.UI.Views
{
    public partial class ProgressView : Form, IProgressView
    {
        public ProgressView()
        {
            InitializeComponent();
        }

        #region Implementation of IProgressView

        /// <summary>
        /// Show the progress dialog.
        /// </summary>
        void IProgressView.ShowDialog()
        {
            base.ShowDialog();
        }

        /// <summary>
        /// Updates the progress value.
        /// </summary>
        /// <param name="newValue">The new progress value. Must be in range [0, 100].</param>
        public void UpdateProgress(int newValue)
        {
            Assert.GreaterOrEqual(newValue, "newValue", 0);
            Assert.LessOrEqual(newValue, "newValue", 100);
            progressBar.Value = newValue;
        }

        /// <summary>
        /// Gets or sets the dialog title.
        /// </summary>
        public string Title
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = String.IsNullOrEmpty(value) ? " " : value;
            }
        }

        /// <summary>
        /// Gets or sets the text displayed in the dialog.
        /// </summary>
        String IProgressView.Text
        {
            get
            {
                return lbText.Text;
            }
            set
            {
                lbText.Text = value;
            }
        }

        public event EventHandler Cancelled;

        #endregion

        private void btnCancel_Click(object sender, EventArgs e)
        {
            var handler = Cancelled;
            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
